<?php
/**
 * Mqtt推送服务
 * zhouliang
 * 2020.09.06
 */

namespace App\Services\Tools;

use Bluerhinos\phpMQTT;

class PushService
{
    const PUSH_POPULARITY                  = 5001;//推送房间-人气变化
    const PUSH_RIDE                        = 5003;//推送房间-坐骑进场特效
    const PUSH_NOBILITY                    = 5004;//推送房间-爵位用户进场特效
    const PUSH_APPLY_COUNT                 = 5005;//推送房间-上麦申请人数变化
    const PUSH_BANNED_USER                 = 5007;//推送房间-用户禁言 1禁言2解禁
    const PUSH_CLOSE_PIT                   = 5011;//推送房间-是否封麦 1封麦2解封
    const PUSH_CLEAR_CARDIAC               = 5013;//推送房间-清空单个麦位心动值
    const PUSH_CLEAR_CARDIAC_ALL           = 5014;//推送房间-清空所有麦位心动值
    const PUSH_SET_MANAGER                 = 5015;//推送房间-设置房间管理员
    const PUSH_DELETE_MANAGER              = 5016;//推送房间-删除房间管理员
    const PUSH_SWITCH_VOICE                = 5017;//推送房间-开关麦 1开0关
    const PUSH_GIFT_BANNER                 = 5019;//推送所有人-横幅礼物通知
    const PUSH_GIFT_CHAT_ROOM              = 5020;//推送房间-聊天室礼物通知
    const PUSH_FISH                        = 5021;//推送所有人-小猫钓鱼钓到大礼物时通知
    const PUSH_ROOM_PASSWORD               = 5022;//推送房间-房间密码变化通知 0取消密码1设置或修改密码
    const PUSH_CARDIAC_SWITCH              = 5023;//推送房间-房间心动值开关变化通知 1开2关
    const PUSH_ROOM_WHEAT                  = 5024;//推送房间-上麦模式变化通知 1自由2排麦
    const PUSH_UPDATE_ROOM_NAME            = 5025;//推送房间-修改房间名称
    const PUSH_WEEK_STAR                   = 5027;//推送房间-周星用户进场特效
    const PUSH_UPDATE_ROOM_BACKGROUND      = 5028;//推送房间-修改房间背景
    const PUSH_UPDATE_ROOM_PLAYING         = 5029;//推送房间-修改房间公告
    const PUSH_BOSS_ATTACK                 = 5030;//推送房间-BOSS大作战 超过99999金币 发送所有人消息
    const PUSH_BOSS_BLOOD                  = 5031;//推送所有正在攻击boss的用户-boss大作战血量变化推送
    const PUSH_PIT_ON                      = 5032;//推送房间-上麦
    const PUSH_PIT_DOWN                    = 5033;//推送房间-下麦
    const PUSH_KICK_OUT                    = 5034;//推送单独用户-被踢出房间
    const PUSH_APPLY_USER                  = 5035;//推送单独用户-定向推向给上麦的用户
    const PUSH_SHUT_UP                     = 5036;//推送房间-用户禁麦 1禁麦2解禁
    const PUSH_JOIN_ROOM                   = 5037;//推送房间-用户进入房间
    const PUSH_COUNT_DOWN                  = 5038;//推送房间-麦位倒计时
    const PUSH_ROLL                        = 5039;//推送房间-扔骰子
    const PUSH_FM_GOLD                     = 5040;//推送所有房间-电台房开通黄金守护
    const PUSH_FACE                        = 5041;//推送房间-在麦上发送表情
    const PUSH_ZEGO_LOG                    = 5042;//推送单独用户-上传即构日志
    const PUSH_ROOM_CHAT_STATUS            = 5043;//推送房间-公屏状态
    const PUSH_BALL_START                  = 5044;//推送房间-球球大作战-开球
    const PUSH_BALL_THROW                  = 5045;//推送房间-球球大作战-弃球
    const PUSH_BALL_SHOW                   = 5046;//推送房间-球球大作战-亮球
    const PUSH_SOUND_EFFECT_CHANGE         = 5047;//推送房间-房间音效改变
    const PUSH_ORDER_RECEIVE               = 5048;//推送大神用户-有用户下单
    const PUSH_ORDER_REFUND                = 5049;//推送给大神-有用户要退款
    const PUSH_ROOM_DEMAND_BOSS            = 5050;//推送单独用户-推送给8号麦的老板
    const PUSH_ROOM_DEMAND_UPDATE          = 5051;//推送房间-更新派单需求
    const PUSH_ROOM_DEMAND_TO_ANCHOR       = 5052;//推送所有用户-将派单需求推送给所有符合条件的大神
    const PUSH_ORDER_MESSAGE               = 5053;//推送所有的订单消息(浮窗形式)
    const PUSH_OFFER_AUCTION               = 5055;//推送房间-拍卖报价
    const PUSH_ABORT_AUCTION               = 5056;//推送房间-拍卖流拍
    const PUSH_END_AUCTION                 = 5057;//推送房间-拍卖成功
    const PUSH_START_AUCTION               = 5058;//推送房间-拍卖开始
    const PUSH_CONNECTION_CP_APPLY         = 5060;//推送单独用户-CP绑定申请
    const PUSH_CONNECTION_MARRY_APPLY      = 5061;//推送单独用户-结婚申请
    const PUSH_JOINROOM_NOTICE             = 5062;//人脉推送单独用户-阶级四进入房间通知
    const PUSH_SINGLE_DRAW                 = 5070;//推送房间-开始抽奖倒计时
    const PUSH_DRAW_RESULT                 = 5071;//推送房间-开奖结果
    const PUSH_DRAW_RESULT_OWNER           = 5072;//推送房主-开奖结果
    const PUSH_THEME_STRIVE_HEADLINE       = 5073;//推送话题广场抢头条通知
    const PUSH_THEME_JOIN_USER_NUMBER      = 5074;//推送话题广场参与人数变化
    const PUSH_SONG_SWITCH                 = 5075;//推送房间-主播更新点歌状态
    const PUSH_NOBILITY_COUNT              = 5076;//推送房间-单人房贵宾人数变化
    const PUSH_SINGLE_SONG_UPDATE          = 5077;//推送房间-单人房歌单变化
    const PUSH_DATING_START                = 5078;//推送房间-开始相亲
    const PUSH_DATING_START_GAME           = 5079;//推送房间-结束第一步开始第二步选择游戏
    const PUSH_DATING_QUESTION             = 5080;//推送房间-默契问答题目变化
    const PUSH_DATING_ADVENTURE_HOLDER     = 5081;//推送房间-选择真心冒险后推送给主持选择嘉宾
    const PUSH_DATING_BEST_MATCH           = 5082;//推送房间-默契问答最佳匹配
    const PUSH_DATING_ADVENTURE_USER       = 5083;//推送房间-嘉宾选择真心冒险游戏类型
    const PUSH_DATING_ADVENTURE_START_GAME = 5084;//推送房间-真心冒险嘉宾选择游戏后开始游戏
    const PUSH_DATING_HEART_CHOICE         = 5085;//推送房间-开始第三步真心抉择
    const PUSH_DATING_CHOOSE_LOVER         = 5086;//推送房间-选择心动对象
    const PUSH_DATING_SHOW_LOVER           = 5087;//推送房间-公布结果
    const PUSH_DATING_END_DATING           = 5088;//推送房间-结束相亲
    const PUSH_DATING_CONFESSION           = 5089;//推送房间-真情告白
    const PUSH_DATING_QUESTION_RESULT      = 5090;//推送房间-默契问答显示题目回答结果
    const PUSH_DATING_RE_CHOOSE            = 5091;//推送房间-真心冒险主持未选择嘉宾的话进入重新选择倒计时
    const PUSH_ROOM_TYPE_CHANGE            = 5100;//全服推送-房间信息变更
    const CROSS_PK_ABNORMAL      = 5106; //跨房PK异常退出

    //家族推送
    const DISSOLVE_FAMILY = 8004;



    public $user_id, $room_id, $topic_room, $topic_client, $delay_seconds;

    /**
     * @var PushChatService
     */
    public $chat;

    public function __construct($user_id = 0, $room_id = 0)
    {
        $this->user_id = $user_id;
        $this->room_id = $room_id;

        $this->topic_room = 'room_'.$this->room_id;
        $this->topic_client = 'user_'.$this->user_id;

        $this->chat = new PushChatService($this->user_id, $this->room_id);
    }

    public function setUser($user_id)
    {
        $this->user_id = $user_id;
        $this->topic_client = 'user_'.$user_id;
    }

    public function setRoom($room_id)
    {
        $this->room_id = $room_id;
        $this->topic_room = 'room_'.$room_id;
    }

    public function setDelay($second)
    {
        $this->delay_seconds = $second;
    }

    private function push($push_type, $topic, $data = [])
    {
        $this->rcQueue($push_type, $topic, $data);
        // 老的 mqtt 推送
//        $this->mqttPush($push_type, $topic, $data);
    }

    private function rcQueue($push_type, $topic, $data = [])
    {
        /**
         * @var $rcService RongCloudService
         */
        $rcService = app('rongcloud');
        $content = [
            'type' => $push_type,
            'time' => (int)(microtime(true) * 1000),
            'msg'  => $data,
        ];

        $delay = 0;
        if ($this->delay_seconds > 0) {
            $delay = $this->delay_seconds;
//            $this->delay_seconds = 0;
        }
        $rcService->queue('system', $topic, ['name' => $topic, 'data' => $content], $delay);
    }

    private function mqttPush($push_type, $topic, $data = [])
    {
        $client_id = 'php-'.uniqid();
        $mqtt = new phpMQTT(env('MQTT_SERVER'), env('MQTT_PORT'), $client_id);
        $mqtt->connect(true, null, env('MQTT_USERNAME'), env('MQTT_PASSWORD'));

        $content = json_encode(
            [
                'type' => $push_type,
                'time' => (int)(microtime(true) * 1000),
                'msg'  => $data,
            ]
        );
        if ($this->delay_seconds > 0) {
            $topic = '$delayed/'.$this->delay_seconds.'/'.$topic;
            $this->delay_seconds = 0;
        }
        $mqtt->publish($topic, $content, 2);
    }

    //推送人气
    public function updatePopularity($popularity)
    {
        $topic = $this->topic_room;
        $this->setDelay(1);
        $data = ['popularity' => $popularity, 'room_id' => $this->room_id];
        $this->push(self::PUSH_POPULARITY, $topic, $data);
    }

    //推送上麦
    public function pitOn($pit_number, $data)
    {
        $topic = $this->topic_room;
        $data['room_id'] = $this->room_id;
        $data['pit_number'] = $pit_number;

        $ball = app('redis')->exists('room:user:ball:'.$this->room_id.':'.$this->user_id);
        $data['ball_state'] = !$ball ? 0 : 1;

        $data['auction_number'] = 0;
        $sys_type_id = app('model_user_room')->getRoomSystemTypeId($this->room_id);
        if (app('model_user_room')->isPmRoom($sys_type_id)) {
            $auction = app('model_auction')->select(['id', 'auction_gift_id'])->where([
                'room_id' => $this->room_id,
                'status'  => 1,
            ])->orderBy('id', 'desc')->first();
            if ($auction) {
                $max = app('model_auction_record')->where([
                    'auction_id' => $auction->id,
                    'user_id'    => $this->user_id,
                ])->orderBy('id', 'desc')->value('total_cost');
                if ($max > 0) {
                    $gift_price = app('model_auction_gift')->where(['id' => $auction->auction_gift_id])->value('gift_price');
                    $data['auction_number'] = $gift_price > 0 ? round($max / $gift_price) : 0;
                }
            }
        }

        $this->push(self::PUSH_PIT_ON, $topic, $data);
    }

    //推送下麦
    public function pitDown($pit_number)
    {
        $topic = $this->topic_room;
        $data = ['room_id' => $this->room_id, 'pit_number' => $pit_number, 'user_id' => $this->user_id];
        $this->push(self::PUSH_PIT_DOWN, $topic, $data);
    }

    //带坐骑用户进场特效通知
    public function ride($ride_info)
    {
        $topic = $this->topic_room;
        $this->setDelay(1);
        $data = [
            'room_id'   => $this->room_id,
            'ride_url'  => $ride_info['special'],
            'show_type' => $ride_info['show_type'],
        ];
        $this->push(self::PUSH_RIDE, $topic, $data);
    }

    //带爵位用户进场特效通知
    public function nobility($data)
    {
        $topic = $this->topic_room;
        $this->setDelay(1);
        if ($data['nobilityId'] == 6) {
            $special = 'https://yutangyuyin.oss-cn-hangzhou.aliyuncs.com/nobility/'.$data['nobilityId'].'.svga';
        } else {
            $special = '';
        }
        $data = [
            'room_id'       => $this->room_id,
            'user_id'       => $this->user_id,
            'nobility_name' => $data['nobilityName'],
            'nobility_id'   => $data['nobilityId'],
            'nobility_icon' => $data['nobility_icon'],
            'avatar'        => $data['headPicture'],
            'nickname'      => $data['userName'],
            'special'       => $special,
            'sex'           => $data['sex'],
        ];
        $this->push(self::PUSH_NOBILITY, $topic, $data);
    }

    //上麦申请人数变化通知
    public function applyCount($count, $user_ids = '')
    {
        $topic = $this->topic_room;

        $count_8 = app('model_room_pit_apply')->where(['room_id' => $this->room_id, 'pit_number' => 8])->count();
        $count_8 = $count_8 > 0 ? $count_8 : 0;

        $total_count = $count - $count_8;
        $data = [
            'room_id'  => $this->room_id,
            'count'    => $total_count > 0 ? $total_count : 0,
            'count_8'  => $count_8,
            'user_ids' => $user_ids,
        ];
        $this->push(self::PUSH_APPLY_COUNT, $topic, $data);
    }

    //用户被禁言 action 1禁言2解禁
    public function bannedUser($action)
    {
        $topic = $this->topic_room;
        $data = ['room_id' => $this->room_id, 'user_id' => $this->user_id, 'action' => $action];
        $this->push(self::PUSH_BANNED_USER, $topic, $data);
    }

    //是否封麦 1.封麦 2.解除封麦
    public function closePit($pit_number, $action)
    {
        $topic = $this->topic_room;
        $data = ['room_id' => $this->room_id, 'pit_number' => $pit_number, 'action' => $action];
        $this->push(self::PUSH_CLOSE_PIT, $topic, $data);
    }

    //清空单个麦位心动值
    public function clearCardiac($pit_number)
    {
        $topic = $this->topic_room;
        $data = ['room_id' => $this->room_id, 'pit_number' => $pit_number];
        $this->push(self::PUSH_CLEAR_CARDIAC, $topic, $data);
    }

    //清空所有麦位心动值
    public function clearCardiacAll()
    {
        $topic = $this->topic_room;
        $data = ['room_id' => $this->room_id];
        $this->push(self::PUSH_CLEAR_CARDIAC_ALL, $topic, $data);
    }

    //设置房间管理员
    public function setManager()
    {
        $topic = $this->topic_room;
        $data = ['room_id' => $this->room_id, 'user_id' => $this->user_id];
        $this->push(self::PUSH_SET_MANAGER, $topic, $data);
    }

    //删除房间管理员
    public function deleteManager()
    {
        $topic = $this->topic_room;
        $data = ['room_id' => $this->room_id, 'user_id' => $this->user_id];
        $this->push(self::PUSH_DELETE_MANAGER, $topic, $data);
    }

    //开关麦 action 1开0关
    public function switchVoice($action, $pit_number = 0)
    {
        $topic = $this->topic_room;
        $data = [
            'room_id'    => $this->room_id,
            'user_id'    => $this->user_id,
            'pit_number' => $pit_number,
            'action'     => $action,
        ];
        $this->push(self::PUSH_SWITCH_VOICE, $topic, $data);
    }

    //横幅礼物通知
    public function giftBanner($gift_list)
    {
        $topic = 'room';
        $data = ['room_id' => $this->room_id, 'list' => $gift_list];
        $this->push(self::PUSH_GIFT_BANNER, $topic, $data);
    }

    //聊天室礼物通知
    public function giftChatRoom($gift_list, $cardiac, $contribution, $show_cat = 0)
    {
        $topic = $this->topic_room;
        $data = [
            'room_id'      => $this->room_id,
            'gift_list'    => $gift_list,
            'cardiac_list' => $cardiac,
            'contribution' => $contribution,
            'show_cat'     => $show_cat,
            'user_id'      => $this->user_id,
        ];
        $this->push(self::PUSH_GIFT_CHAT_ROOM, $topic, $data);
    }

    //聊天室礼物通知
    public function giftChatAuctionRoom($gift_list)
    {
        $topic = $this->topic_room;
        $data = [
            'room_id'      => $this->room_id,
            'gift_list'    => $gift_list,
            'cardiac_list' => [],
            'contribution' => 0,
            'show_cat'     => 0,
            'user_id'      => $this->user_id,
        ];
        $this->push(self::PUSH_GIFT_CHAT_ROOM, $topic, $data);
    }

    //小猫钓鱼钓到大礼物时通知
    public function fish($gift_list, $user_info)
    {
        $txt = "<font color='#FFFFFF'>哇塞</font><font color='#FD8469'>".$user_info['nickname']."</font><font color='#FFFFFF'>在小猫钓鱼中获得</font>";
        $txt_extra = [];
        foreach ($gift_list as $key => $value) {
            if ($value['price'] >= 99999) {
                $txt_extra [] = [
                    'text'    => $txt."<font color='#FABA5C'>".$value['prize_title']."</font><font color='#FFFFFF'>X".$value['number']."</font>",
                    'picture' => $value['picture'],
                ];
            }
        }
        if (!empty($txt_extra)) {
            $topic = 'room';
            $this->push(self::PUSH_FISH, $topic, $txt_extra);
        }
    }

    //房间密码 0取消密码1设置或修改密码
    public function roomPassword($action)
    {
        $topic = $this->topic_room;
        $data = ['room_id' => $this->room_id, 'action' => $action];
        $this->push(self::PUSH_ROOM_PASSWORD, $topic, $data);
    }

    //房间心动值开关 1开2关
    public function cardiacSwitch($action)
    {
        $topic = $this->topic_room;
        $data = ['room_id' => $this->room_id, 'action' => $action];
        $this->push(self::PUSH_CARDIAC_SWITCH, $topic, $data);
    }

    //上麦模式变化 1自由2排麦
    public function roomWheat($action)
    {
        $topic = $this->topic_room;
        $data = ['room_id' => $this->room_id, 'action' => $action];
        $this->push(self::PUSH_ROOM_WHEAT, $topic, $data);
    }

    //修改房间名称
    public function updateRoomName($room_name)
    {
        $topic = $this->topic_room;
        $data = ['room_id' => $this->room_id, 'room_name' => $room_name];
        $this->push(self::PUSH_UPDATE_ROOM_NAME, $topic, $data);
    }

    //周星用户进场
    public function weekStar($nickname, $rank)
    {
        $topic = $this->topic_room;
        $data = ['room_id' => $this->room_id, 'nickname' => $nickname, 'rank' => $rank];
        $this->push(self::PUSH_WEEK_STAR, $topic, $data);
    }

    //修改房间背景
    public function updateRoomBackground($background)
    {
        $topic = $this->topic_room;
        $data = ['room_id' => $this->room_id, 'background' => $background];
        $this->push(self::PUSH_UPDATE_ROOM_BACKGROUND, $topic, $data);
    }

    //修改房间公告
    public function updateRoomPlaying($playing)
    {
        $topic = $this->topic_room;
        $data = ['room_id' => $this->room_id, 'playing' => $playing];
        $this->push(self::PUSH_UPDATE_ROOM_PLAYING, $topic, $data);
    }

    //boss大作战 超过99999金币 发送所有人消息

    public function AttackBoss($gift_list, $user_info)
    {
        $txt = "<font color='#FFFFFF'>哇塞</font><font color='#FD8469'>".$user_info['nickname']."</font><font color='#FFFFFF'>在BOSS大作战中获得</font>";
        $txt_extra = [];
        foreach ($gift_list as $key => $value) {
            if ($value['price'] >= 52000) {
                $txt_extra [] = [
                    'text'    => $txt."<font color='#FABA5C'>".$value['prize_title']."</font><font color='#FFFFFF'>X".$value['number']."</font>",
                    'picture' => $value['picture'],
                ];
            }
        }
        if (!empty($txt_extra)) {
            $topic = 'room';
            $this->push(self::PUSH_BOSS_ATTACK, $topic, $txt_extra);
        }
    }

    //boss大作战血量变化推送
    public function bossBlood($left_blood = 0, $total_blood = 0, $gift_list = [], $user_info = [])
    {
        if ($gift_list) {
            foreach ($gift_list as $key => $value) {
                if ($value['price'] >= 5200) {
                    $gift_list[$key]['nickname'] = $user_info['nickname'];
                } else {
                    unset($gift_list[$key]);
                }
            }
        }
        $topic = 'boss';
        $data = ['left_blood' => $left_blood, 'total_blood' => $total_blood, 'gift_list' => array_values($gift_list)];
        $this->push(self::PUSH_BOSS_BLOOD, $topic, $data);
    }

    //定向推送给上麦的用户
    public function agreeApplyUser($pit_number)
    {
        $topic = $this->topic_client;
        $data = ['room_id' => $this->room_id, 'pit_number' => $pit_number];
        $this->push(self::PUSH_APPLY_USER, $topic, $data);
    }

    //定向推送给被踢出房间的用户
    public function kickOut()
    {
        $topic = $this->topic_client;
        $data = ['room_id' => $this->room_id, 'user_id' => $this->user_id];
        $this->push(self::PUSH_KICK_OUT, $topic, $data);
    }

    //用户禁麦 action 1禁麦2解禁
    public function shutUp($action, $pit_number)
    {
        $topic = $this->topic_room;
        $data = [
            'room_id'    => $this->room_id,
            'action'     => $action,
            'pit_number' => $pit_number,
            'user_id'    => $this->user_id,
        ];
        $this->push(self::PUSH_SHUT_UP, $topic, $data);
    }

    //用户进入房间
    public function joinRoom($nickname, $rank_icon, $role, $user_is_new)
    {
        $topic = $this->topic_room;

        //用户个性装扮：进场特效
        $special = RedisService::getJoinSpecial($this->user_id);

        $data = [
            'room_id'     => $this->room_id,
            'user_id'     => $this->user_id,
            'nickname'    => $nickname,
            'rank_icon'   => $rank_icon,
            'role'        => $role,
            'user_is_new' => $user_is_new,
            'background'  => $special['picture'] ?? '',
            'color'       => $special['special'] ?? '',
        ];

        $this->push(self::PUSH_JOIN_ROOM, $topic, $data);
    }

    //麦位倒计时
    public function countDown($pit_number, $seconds)
    {
        $topic = $this->topic_room;
        $data = ['room_id' => $this->room_id, 'pit_number' => $pit_number, 'seconds' => $seconds];
        $this->push(self::PUSH_COUNT_DOWN, $topic, $data);
    }

    //扔骰子
    public function roll($number, $pit_number)
    {
        $topic = $this->topic_room;
        $data = [
            'room_id'    => $this->room_id,
            'user_id'    => $this->user_id,
            'number'     => $number,
            'pit_number' => $pit_number,
        ];
        $this->push(self::PUSH_ROLL, $topic, $data);
    }

    //电台房开通黄金守护
    public function fmGold($nickname_from, $nickname_to)
    {
//        $topic = 'room';
        $topic = $this->topic_room;
        $data = ['room_id' => $this->room_id, 'nickname_from' => $nickname_from, 'nickname_to' => $nickname_to];
        $this->push(self::PUSH_FM_GOLD, $topic, $data);
    }

    //发送表情
    public function face($pit_number, $picture, $special)
    {
        $topic = $this->topic_room;
        $data = [
            'room_id'    => $this->room_id,
            'pit_number' => $pit_number,
            'picture'    => $picture,
            'special'    => $special,
        ];
        $this->push(self::PUSH_FACE, $topic, $data);
    }

    //上传即构日志
    public function zegoLog()
    {
        $topic = $this->topic_client;
        $data = ['user_id' => $this->user_id];
        $this->push(self::PUSH_ZEGO_LOG, $topic, $data);
    }

    //公屏状态
    public function roomChatStatus($status)
    {
        $topic = $this->topic_room;
        $data = ['room_id' => $this->room_id, 'status' => $status];
        $this->push(self::PUSH_ROOM_CHAT_STATUS, $topic, $data);
    }

    //球球大作战-开球
    public function ballStart($pit_number)
    {
        $topic = $this->topic_room;
        $data = ['room_id' => $this->room_id, 'pit_number' => $pit_number];
        $this->push(self::PUSH_BALL_START, $topic, $data);
    }

    //球球大作战-弃球
    public function ballThrow($pit_number)
    {
        $topic = $this->topic_room;
        $data = ['room_id' => $this->room_id, 'pit_number' => $pit_number];
        $this->push(self::PUSH_BALL_THROW, $topic, $data);
    }

    //球球大作战-亮球
    public function ballShow($pit_number, $first, $second, $third)
    {
        $topic = $this->topic_room;
        $data = [
            'room_id'    => $this->room_id,
            'pit_number' => $pit_number,
            'first'      => $first,
            'second'     => $second,
            'third'      => $third,
            'user_id'    => $this->user_id,
        ];
        $this->push(self::PUSH_BALL_SHOW, $topic, $data);
    }

    //房间音效改变
    public function soundEffectChange($sound_effect_detail)
    {
        $topic = $this->topic_room;
        $data = [
            'room_id' => $this->room_id,
            'id'      => $sound_effect_detail['id'],
            'config'  => $sound_effect_detail['config'],
        ];
        $this->push(self::PUSH_SOUND_EFFECT_CHANGE, $topic, $data);
    }

    //用户下单--给大神推送通知消息
    public function sendOrderMessage($data)
    {
        $topic = $this->topic_client;
        $this->push(self::PUSH_ORDER_RECEIVE, $topic, $data);
    }

    //用户申请退款--给大神推送通知消息
    public function sendRefundMessage($data)
    {
        $topic = $this->topic_client;
        $this->push(self::PUSH_ORDER_REFUND, $topic, $data);
    }

    //派单厅-将麦上的主播推送给8号麦的老板
    public function roomDemandToBoss($data)
    {
        $topic = $this->topic_client;
        $this->push(self::PUSH_ROOM_DEMAND_BOSS, $topic, $data);
    }

    //派单厅-更新派单需求
    public function roomDemandUpdate($data)
    {
        $topic = $this->topic_room;
        $this->push(self::PUSH_ROOM_DEMAND_UPDATE, $topic, $data);
    }

    //派单厅-将派单需求推送给所有符合条件的大神
    public function roomDemandToAnchor($data)
    {
        $topic = 'room';
        $this->push(self::PUSH_ROOM_DEMAND_TO_ANCHOR, $topic, $data);
    }

    //订单消息推送(简单的消息浮窗)
    public function pushOrderMessage($data)
    {
        $topic = $this->topic_client;
        $this->push(self::PUSH_ORDER_MESSAGE, $topic, $data);
    }

    //推送房间-拍卖开始
    public function startAuction($data)
    {
        $topic = $this->topic_room;
        $this->push(self::PUSH_START_AUCTION, $topic, $data);
    }

    //推送房间-拍卖报价
    public function offerAuction($data)
    {
        $topic = $this->topic_room;
        $this->push(self::PUSH_OFFER_AUCTION, $topic, $data);
    }

    //推送房间-拍卖流拍
    public function abortAuction($data)
    {
        $topic = $this->topic_room;
        $this->push(self::PUSH_ABORT_AUCTION, $topic, $data);
    }

    //推送房间-拍卖成功
    public function endAuction($data)
    {
        $topic = $this->topic_room;
        $this->push(self::PUSH_END_AUCTION, $topic, $data);
    }

    //人脉-CP绑定申请
    public function cpApply($data)
    {
        $topic = $this->topic_client;
        $this->push(self::PUSH_CONNECTION_CP_APPLY, $topic, $data);
    }

    //人脉-结婚申请
    public function marryApply($data)
    {
        $topic = $this->topic_client;
        $this->push(self::PUSH_CONNECTION_MARRY_APPLY, $topic, $data);
    }

    //人脉-结婚申请
    public function publishDraw($data)
    {
        $topic = $this->topic_room;
        $this->push(self::PUSH_SINGLE_DRAW, $topic, $data);
    }

    //人脉-阶级四进入房间推送
    public function joinroomNotice($data)
    {
        $topic = $this->topic_client;
        $this->push(self::PUSH_JOINROOM_NOTICE, $topic, $data);
    }

    //推送房间所有用户-开奖结果
    public function drawResult($data)
    {
        $topic = $this->topic_room;
        $this->push(self::PUSH_DRAW_RESULT, $topic, $data);
    }

    //推送房主-开奖结果
    public function drawResultOwner($data)
    {
        $topic = $this->topic_client;
        $this->push(self::PUSH_DRAW_RESULT_OWNER, $topic, $data);
    }

    // 推送话题广场抢头条通知
    public function themeStriveHeadline($data)
    {
        $this->push(self::PUSH_THEME_STRIVE_HEADLINE, "theme_push", $data);
    }

    // 推送话题广场参与人数变化
    public function themeJoinUserNumber($data)
    {
        $this->push(self::PUSH_THEME_JOIN_USER_NUMBER, "theme_push", $data);
    }

    //推送房间用户-主播更新点歌状态1开启2关闭
    public function songSwitch($data)
    {
        $topic = $this->topic_room;
        $this->push(self::PUSH_SONG_SWITCH, $topic, $data);
    }

    //单人房贵宾人数通知
    public function nobilityCount()
    {
        $topic = $this->topic_room;
        $count = app('repo_single_room')->nobilityUserCount($this->room_id);
        $data = [
            'room_id' => $this->room_id,
            'count'   => $count,
        ];
        $this->push(self::PUSH_NOBILITY_COUNT, $topic, $data);
    }

    //单人房歌单变化通知
    public function singleSongUpdate()
    {
        $topic = $this->topic_room;
        $data = [
            'room_id' => $this->room_id,
        ];
        $this->push(self::PUSH_SINGLE_SONG_UPDATE, $topic, $data);
    }

    public function startDating($data)
    {
        $topic = $this->topic_room;
        $data['step'] = 1;
        $data['desc'] = '';//客户端显示倒计时
        $this->push(self::PUSH_DATING_START, $topic, $data);
    }

    public function startGame($data)
    {
        $topic = $this->topic_room;
        $data['step'] = 2;
        $data['desc'] = '主持人选择中...';
        $this->push(self::PUSH_DATING_START_GAME, $topic, $data);
    }

    public function datingQuestion($data)
    {
        $topic = $this->topic_room;
        $data['step'] = 2;
        $data['desc'] = '默契问答中...';
        $this->push(self::PUSH_DATING_QUESTION, $topic, $data);
    }

    public function adventureHolder($data)
    {
        $topic = $this->topic_room;
        $data['step'] = 2;
        $data['desc'] = '主持人选择嘉宾中...';
        $this->push(self::PUSH_DATING_ADVENTURE_HOLDER, $topic, $data);
    }

    public function datingBestMatch($data)
    {
        $topic = $this->topic_room;
        $data['step'] = 2;
        $data['desc'] = '默契度匹配中...';
        $this->push(self::PUSH_DATING_BEST_MATCH, $topic, $data);
    }

    public function adventureUser($data)
    {
        $topic = $this->topic_room;
        $data['step'] = 2;
        $data['desc'] = '号麦选择中...';
        $this->push(self::PUSH_DATING_ADVENTURE_USER, $topic, $data);
    }

    public function chooseGameByUser($data)
    {
        $topic = $this->topic_room;
        $data['step'] = 2;
        $this->push(self::PUSH_DATING_ADVENTURE_START_GAME, $topic, $data);
    }

    public function startHeartChoice($data)
    {
        $topic = $this->topic_room;
        $data['step'] = 3;
        $data['desc'] = '';//客户端显示倒计时
        $this->push(self::PUSH_DATING_HEART_CHOICE, $topic, $data);
    }

    public function chooseLover($data)
    {
        $topic = $this->topic_room;
        $data['step'] = 3;
        $data['desc'] = '';//客户端显示倒计时
        $this->push(self::PUSH_DATING_CHOOSE_LOVER, $topic, $data);
    }

    public function showLover($data)
    {
        $topic = $this->topic_room;
        $data['step'] = 4;
        $data['desc'] = '结果公布中...';
        $this->push(self::PUSH_DATING_SHOW_LOVER, $topic, $data);
    }

    public function endDating($data)
    {
        $topic = $this->topic_room;
        $data['step'] = 0;
        $data['desc'] = '等待嘉宾上麦...';
        $this->push(self::PUSH_DATING_END_DATING, $topic, $data);
    }

    public function confession($data)
    {
        $topic = $this->topic_room;
        $data['step'] = 5;
        $data['desc'] = '';//客户端显示倒计时
        $this->push(self::PUSH_DATING_CONFESSION, $topic, $data);
    }

    public function datingQuestionResult($data)
    {
        $topic = $this->topic_room;
        $data['step'] = 2;
        $data['desc'] = '默契问答中...';
        $this->push(self::PUSH_DATING_QUESTION_RESULT, $topic, $data);
    }

    public function reChoose($data)
    {
        $topic = $this->topic_room;
        $data['step'] = 2;
        $data['desc'] = '';//倒计时
        $this->push(self::PUSH_DATING_RE_CHOOSE, $topic, $data);
    }
    
    public function roomTypeChange($data){
        $topic = 'theme_push';
        $this->push(self::PUSH_ROOM_TYPE_CHANGE, $topic, $data);
    }

    //跨房pk异常结束
    public function abnormalEnd(array $data)
    {
        $this->push(self::CROSS_PK_ABNORMAL, $this->topic_room, $data);
    }
}

